﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Serialization;
using ExcelUtils;
using TestEngine.Script;
using TestEngine.Script.Task;

namespace TestEngine
{
    [Serializable]
    [XmlInclude(typeof(OpenWorkbookTask))]
    [XmlInclude(typeof(CreateSessionTask))]
    [XmlInclude(typeof(CloseSessionTask))]
    [XmlInclude(typeof(ApplyInputsTask))]
    [XmlInclude(typeof(GetOutputsTask))]
    [XmlInclude(typeof(CalculateSheetTask))]
    public abstract class ScriptTask
    {

        #region Private Members

        private Exception _exception;
        
        #endregion Private Members

        #region Public Properties
        
        public bool IsError
        {
            get
            {
                return _exception != null;
            }
        }

        #endregion Public Properties

        #region Public Methods

        public bool RunTask(ScriptState state)
        {
            try
            {
                return RunTaskSub(state);
            }
            catch (Exception ex)
            {
                _exception = ex;
            }
            return false;
        }
        
        #endregion Public Methods

        #region Protected Methods

        protected abstract bool RunTaskSub(ScriptState state);

        #endregion Protected Methods
    }
}
